.TH std::ranges::enumerate_view::size 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::ranges::enumerate_view::size \- std::ranges::enumerate_view::size

.SH Synopsis
   constexpr auto size() requires ranges::sized_range<V>;             \fB(1)\fP (since C++23)
   constexpr auto size() const requires ranges::sized_range<const V>; \fB(2)\fP (since C++23)

   Returns the number of elements. Equivalent to return ranges::size(base_);, where
   base_ is the underlying view.

.SH Parameters

   \fI(none)\fP

.SH Return value

   The number of elements.

.SH Example


// Run this code

 #include <cassert>
 #include <forward_list>
 #include <ranges>
 #include <string_view>

 int main()
 {
     constexpr static auto v1 = {1, 2, 3, 4, 5};
     constexpr auto ev1{v1 | std::views::enumerate};
     static_assert(ev1.size() == 5);
     static_assert(std::ranges::sized_range<decltype(v1)>);

     auto v2 = std::forward_list{1, 2, 3, 4, 5};
     auto ev2 {v2 | std::views::enumerate};
     static_assert(not std::ranges::sized_range<decltype(v2)>);
     // auto size = ev2.size(); // Error: v2 is not a sized range
     assert(std::ranges::distance(v2) == 5); // OK, distance does not require sized
                                             // range, but has O(N) complexity here
 }

.SH See also

   ranges::size  returns an integer equal to the size of a range
   (C++20)       (customization point object)
   ranges::ssize returns a signed integer equal to the size of a range
   (C++20)       (customization point object)
